﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace HOAU
{
    public partial class MiniInputPanel : UserControl
    {
        private List<string> displayKeys;
        private EventHandler clickEventHandler;

        public MiniInputPanel(EventHandler clickEventHandler)
        {
            InitializeComponent();

            this.clickEventHandler = clickEventHandler;

            displayKeys = new List<string>();
            for (int i = 1; i < 10; i++)
            {
                displayKeys.Add(i.ToString());
            }
            displayKeys.Add("0");
            //displayKeys.Add("`");
            displayKeys.Add("~");
            displayKeys.Add("!");
            displayKeys.Add("@");
            displayKeys.Add("#");
            displayKeys.Add("$");
            displayKeys.Add("%");
            displayKeys.Add("^");
            displayKeys.Add("&");
            displayKeys.Add("*");
            displayKeys.Add("(");
            displayKeys.Add(")");
            //displayKeys.Add("-");
            //displayKeys.Add("_");
            //displayKeys.Add("+");
            //displayKeys.Add("=");
            //displayKeys.Add("[");
            //displayKeys.Add("]");
            //displayKeys.Add("{");
            //displayKeys.Add("}");
            //displayKeys.Add("\\");
            //displayKeys.Add("|");
            //displayKeys.Add(";");
            //displayKeys.Add(":");
            //displayKeys.Add("\"");
            //displayKeys.Add(",");
            //displayKeys.Add("<");
            //displayKeys.Add(".");
            //displayKeys.Add(">");
            //displayKeys.Add("/");
            //displayKeys.Add("?");

            CreateKeyboardLabel();
        }

        private void CreateKeyboardLabel()
        {
            if (displayKeys == null || displayKeys.Count <= 0)
            {
                return;
            }

            int widthHight = 20;

            this.Size = new Size(204, widthHight * ((displayKeys.Count / 10) + 2));

            KeyboardLabel kbLabel = null;
            Size size = new Size(widthHight, widthHight);
            int x = 1, y = 1;

            for (int i = 0; i < displayKeys.Count; i++)
            {
                kbLabel = new KeyboardLabel();
                kbLabel.Name = String.Format("kbLabel{0}", i);
                kbLabel.Size = size;
                kbLabel.Location = new Point(x, y);
                kbLabel.Text = displayKeys[i];
                kbLabel.ClickEventHandler += this.clickEventHandler;
                x += widthHight;
                if (x >= 200)   // 10 keys per line
                {
                    x = 1;
                    y += widthHight;
                }

                this.Controls.Add(kbLabel);
            }

            kbLabel = new KeyboardLabel();
            kbLabel.Name = "kbLabelHide";
            kbLabel.Size = new Size(40, widthHight);

            kbLabel.Location = new Point(this.Size.Width - 43, this.Size.Height - (widthHight + 3));
            kbLabel.Text = "隐藏";
            kbLabel.ClickEventHandler += this.clickEventHandler;

            this.Controls.Add(kbLabel);
        }
    }
}
